jQuery(document).ready(function($){
	$('.upload-section input[type="button"]').click(function(e){
		e.preventDefault();
		var active_id = $(this).closest(".upload-section").data("id")
		var mine_uploader = wp.media({
			title: 'Select or upload an image',
			button: { text: 'Select It' },
			multiple: false
		}).on('select', function(){
			var attachment = mine_uploader.state().get('selection').first().toJSON();
			// 通过.length 判断元素是否存在
			if ($('#' + active_id).length > 0) {
				$('#' + active_id).val(attachment.url);
			}
			if ($('#' + active_id + '-image').length > 0) {
				$('#' + active_id + '-image').val(attachment.url);
			}
		}).open();

	});
});
